//
//  ChatMessageResolver.m
//  AtWork2
//
//  Created by lucas on 15/5/29.
//  Copyright (c) 2015年 Foreveross. All rights reserved.
//

#import "AWChatMessageResolver.h"
#import "AWChatMessage.h"
#import "AWTextChatMessage.h"
#import "AWImageChatMessage.h"
#import "AWVoiceChatMessage.h"
#import "AWFileChatMessage.h"
#import "AWArticleChatMessage.h"

@implementation AWChatMessageResolver

+ (AWChatMessage *)resolveIfPossibleWithDictionary:(NSDictionary *)message {
    if (nil == message[AWMessageKBody][AWMessageKType]) { // NOTE: 服务号可能没有类型。
        return nil;
    }
    AWChatMessageType type = parseChatMessageType(message[AWMessageKBody][AWMessageKType]);
    switch (type) {
        case AWChatMessageTypeText:
            return [self resolveToTextMessageWithDictionary:message];
        case AWChatMessageTypeImage:
            return [self resolveToImageMessageWithDictionary:message];
        case AWChatMessageTypeVoice:
            return [self resolveToVoiceMessageWithDictionary:message];
        case AWChatMessageTypeFile:
            return [self resolveToFileMessageWithDictionary:message];
        case AWChatMessageTypeArticle:
            return [self resolveToArtcleMessageWithDictionary:message];
        case AWChatMessageTypeEvent:
        case AWChatMessageTypeSystem:
            return nil; // NOTE: 事件、系统消息类型都是移动端本地的。
    }
}

+ (AWChatMessage *)resolveToTextMessageWithDictionary:(NSDictionary *)message {
    return [AWTextChatMessage messageWithDictionary:message];
}

+ (AWChatMessage *)resolveToImageMessageWithDictionary:(NSDictionary *)message {
    return [AWImageChatMessage messageWithDictionary:message];
}

+ (AWChatMessage *)resolveToVoiceMessageWithDictionary:(NSDictionary *)message {
    return [AWVoiceChatMessage messageWithDictionary:message];
}

+ (AWChatMessage *)resolveToFileMessageWithDictionary:(NSDictionary *)message {
    return [AWFileChatMessage messageWithDictionary:message];
}

+ (AWChatMessage *)resolveToArtcleMessageWithDictionary:(NSDictionary *)message {
    return [AWArticleChatMessage messageWithDictionary:message];
}

@end
